var prefix = jsctx + "/elecStation/operator";

var station = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listStation",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    cache: false,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            stationName: $("#stationName").val().trim(),
                            operateStatus: $("#operateStatus").val().trim(),
                            areaId: $("#areaId").val().trim(),
                            stationNo: $("#stationNo").val().trim(),
                            bizType: $("#bizType").val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '',width:'50',align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'stationNo', title: '桩群编号', width:'100',align: 'left'},
                        {field: 'stationName', title: '桩群名称', width:'100',align: 'left'},
                        {field: 'address', title: '地址详情', width:'100',align: 'left'},
                        {
                            field: 'stationType', title: '站点类型',width:'100',align: 'left',
                            formatter: function (value, row, index) {
                                if (value == '1') {
                                    return '<span >公共</span>'
                                } else if (value == '50') {
                                    return '<span >个人</span>'
                                } else if (value == '100') {
                                    return '<span >公交(专用)</span>'
                                } else if (value == '101') {
                                    return '<span >环卫(专用)</span>'
                                } else if (value == '102') {
                                    return '<span >物流(专用)</span>'
                                } else if (value == '103') {
                                    return '<span >出租车(专用)</span>'
                                } else if (value == '255') {
                                    return '<span >其他</span>'
                                }
                            }
                        },
                        // {
                        //     field: 'bizType', title: '营业类型',
                        //     width:'100',align: 'center',
                        //     formatter: function (value, row, index) {
                        //         if (value == '0') {
                        //             return '<span class="label label-primary">自营</span>'
                        //         } else if (value == '1') {
                        //             return '<span class="label label-success">非自营</span>'
                        //         }
                        //     }
                        // },
                        {
                            field: 'elecType', title: '充电类型',
                            width:'100',align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-warning">正常充电</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-danger">插枪立即充电(VIN)</span>'
                                }
                            }
                        },
                        {
                            field: 'operateStatus', title: '运营状态',
                            width:'100',align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '<span class="label label-success">未上线</span>'
                                } else if (value == '1') {
                                    return '<span class="label label-info">上线</span>'
                                } else if (value == '2') {
                                    return '<span class="label label-danger">下线</span>'
                                }
                            }
                        },
                        {
                            title: '操作',
                            field: 'roleId',
                            width:'200',align: 'center',
                            formatter: function (value, row, index) {
                                var a = '<a class="btn btn-primary btn-sm ' + has_edit + '" href="#" title="桩列表" onclick="station.pileListPage(\''
                                    + row.elecStationId
                                    + '\')">桩列表</a> ';

                                var f = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="详情" onclick="station.detailStation(\''
                                    + row.elecStationId
                                    + '\')">详情</a> ';

                                return f + a;
                            }
                        }
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }


    //桩页面
    function pileListPage(elecStationId) {
        location.href = prefix + "/operatorPileListPage/" + elecStationId;
    }


    function goBack() {
        location.href = prefix + "/index";
    }

    function detailStation(elecStationId) {
        location.href = jsctx + "/elecStation/detailStation/" + elecStationId;
    }

    function exportStation() {
        var stationName = $("#stationName").val().trim(),
            operateStatus = $("#operateStatus").val().trim(),
            areaId = $("#areaId").val().trim(),
            count = $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),

            offset = $('.active .page-link').text(),
            limit = $(".page-size").text();

        location.href = prefix + "/exportStation?stationName=" + stationName + "&operateStatus=" + operateStatus + "&areaId=" + areaId
            + "&count=" + count + "&offset=" + offset + "&limit=" + limit;
    }


    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        pileListPage: pileListPage,
        exportStation: exportStation,
        detailStation: detailStation
    };
})();
